package com.cn.bukeManage.controller;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.cn.bukeManage.pojo.Customer;
import com.cn.bukeManage.pojo.Dealer;
import com.cn.bukeManage.pojo.Supplier;
import com.cn.bukeManage.pojo.Worker;
import com.cn.bukeManage.service.MemberService;

//这是会员管理
@Controller
@RequestMapping("/member")
public class MemberController {
	@Resource
	private MemberService memberservice;
	
	//顾客管理
	@RequestMapping(value={"/customer"})
	public String customer(Model model,Integer currentPage){
		List<Customer> customers=memberservice.getAllCustomerByPage(model,currentPage);
		model.addAttribute("oneMenu","member");
		model.addAttribute("twoMenu","customer");
		model.addAttribute("customers",customers);
		return "member/customer";
	}
	
	
	
	//停用顾客或经销商子账号
	@RequestMapping("/toUpdatecustomer")
	@ResponseBody
	public Integer toUpdatecustomer(Integer customerId){
		Integer integer = memberservice.toUpdatecustomer(customerId);
		return integer;
	}
	//根据注册时间降序排序
	@RequestMapping("/customerJ")
	public String customerJ(Model model,Integer currentPage){
		List<Customer> customers=memberservice.getAllCustomerByPageJ(model,currentPage);
		model.addAttribute("oneMenu","member");
		model.addAttribute("twoMenu","customer");
		model.addAttribute("customers",customers);
		return "member/Jcustomer";
	}
	//根据注册时间升序排序
	@RequestMapping("/customerS")
	public String customerS(Model model,Integer currentPage){
		List<Customer> customers=memberservice.getAllCustomerByPageS(model,currentPage);
		model.addAttribute("oneMenu","member");
		model.addAttribute("twoMenu","customer");
		model.addAttribute("customers",customers);
		return "member/Scustomer";
	}
	//搜索顾客
	@RequestMapping("/searchCustomer")
	public String searchCustomer(Model model,Integer currentPage,String search){
		List<Customer> customers=memberservice.searchCustomer(model,currentPage,search);
		model.addAttribute("oneMenu","member");
		model.addAttribute("twoMenu","customer");
		model.addAttribute("customers",customers);
		model.addAttribute("search",search.trim());
		return "member/searchCustomer";
	}
	//经销商管理
	@RequestMapping("dealer")
	public String dealer(Model model,Integer currentPage){
		List<Dealer> dealers=memberservice.getAllDealerByPage(model,currentPage);
		model.addAttribute("oneMenu","member");
		model.addAttribute("twoMenu","dealer");
		model.addAttribute("dealers",dealers);
		return "member/dealer";
	}
	//根据注册时间降序排序经销商
	@RequestMapping("/dealerJ")
	public String dealerJ(Model model,Integer currentPage){
		List<Dealer> dealers=memberservice.getAllDealerByPageJ(model,currentPage);
		model.addAttribute("oneMenu","member");
		model.addAttribute("twoMenu","dealer");
		model.addAttribute("dealers",dealers);
		return "member/Jdealer";
	}
	//根据注册时间升序进行排序经销商
	@RequestMapping("/dealerS")
	public String dealerS(Model model,Integer currentPage){
		List<Dealer> dealers=memberservice.getAllDealerByPageS(model,currentPage);
		model.addAttribute("oneMenu","member");
		model.addAttribute("twoMenu","dealer");
		model.addAttribute("dealers",dealers);
		return "member/Sdealer";
	}
	//搜索经销商
	@RequestMapping("/searchDealer")
	public String searchDealer(Model model,String search){
		List<Dealer> dealers=memberservice.searchDealer(model,search);
		model.addAttribute("oneMenu","member");
		model.addAttribute("twoMenu","dealer");
		model.addAttribute("dealers",dealers);
		model.addAttribute("search",search.trim());
		return "member/dealer";
	}
	//停用经销商
	@RequestMapping("/toUpdatedealer")
	@ResponseBody
	public Integer toUpdatedealer(Integer dealerId){
		Integer integer = memberservice.toUpdatedealer(dealerId);
		return integer;
	}
	//供应商管理
	@RequestMapping("supplier")
	public String supplier(Model model,Integer currentPage){
		List<Supplier> suppliers=memberservice.getAllSupplierByPage(model,currentPage);
		model.addAttribute("oneMenu","member");
		model.addAttribute("twoMenu","supplier");
		model.addAttribute("suppliers", suppliers);
		return "member/supplier";
	}
	//工人管理
	@RequestMapping("worker")
	public String worker(Model model,Integer currentPage){
		List<Worker> workers=memberservice.getAllWorkerByPage(model,currentPage);
		model.addAttribute("oneMenu","member");
		model.addAttribute("twoMenu","worker");
		model.addAttribute("workers", workers);
		return "member/worker";
	}
	//根据注册时间降序排序工人
	@RequestMapping("/workerJ")
	public String workerJ(Model model,Integer currentPage){
		List<Worker> workers=memberservice.getAllWorkerByPageJ(model,currentPage);
		model.addAttribute("oneMenu","member");
		model.addAttribute("twoMenu","worker");
		model.addAttribute("workers", workers);
		return "member/Jworker";
	}
	//根据注册时间降序排序工人
	@RequestMapping("/workerS")
	public String workerS(Model model,Integer currentPage){
		List<Worker> workers=memberservice.getAllWorkerByPageS(model,currentPage);
		model.addAttribute("oneMenu","member");
		model.addAttribute("twoMenu","worker");
		model.addAttribute("workers", workers);
		return "member/Sworker";
	}
	//搜索工人
	@RequestMapping("/searchWorker")
	public String searchWorker(Model model,Integer currentPage,String search){
		List<Worker> workers=memberservice.searchWorker(model,currentPage,search);
		model.addAttribute("oneMenu","member");
		model.addAttribute("twoMenu","worker");
		model.addAttribute("workers", workers);
		model.addAttribute("search",search.trim());
		return "member/searchWorker";
	}
	//停用工人
	@RequestMapping("/toUpdateworker")
	@ResponseBody
	public Integer toUpdateworker(Integer workerId){
		Integer integer = memberservice.toUpdateworker(workerId);
		return integer;
	}
	//商家管理
	@RequestMapping("business")
	public String business(Model model,Integer currentPage){
		model.addAttribute("oneMenu","member");
		model.addAttribute("twoMenu","business");
		return "member/business";
	}
	//根据id查询供货商
	@RequestMapping("/selectSupplier")
	@ResponseBody
	public Supplier selectSupplier(Integer supplierId){
		Supplier supplier = memberservice.selectSupplier(supplierId);
		return supplier;
	}
	//根据id修改供货商
	@RequestMapping("/saveSupplier")
	@ResponseBody
	public Integer saveSupplier(Supplier supplier){
		Integer integer = memberservice.saveSupplier(supplier);
		return integer;
	}
	//删除供货商
	@RequestMapping("/deleteSupplier")
	@ResponseBody
	public Integer deleteSupplier(Integer supplierId){
		Integer integer = memberservice.deleteSupplier(supplierId);
		return integer;
	}
	//添加供货商
	@RequestMapping("/insertSupplier")
	@ResponseBody
	public Integer insertSupplier(Supplier supplier){
		Integer integer = memberservice.insertSupplier(supplier);
		return integer;
	}
	//搜索供货商
	@RequestMapping("/searchSupplier")
	public String searchSupplier(Model model,Integer currentPage,String search){
		List<Supplier> suppliers=memberservice.searchSupplier(model,currentPage,search);
		model.addAttribute("oneMenu","member");
		model.addAttribute("twoMenu","supplier");
		model.addAttribute("suppliers", suppliers);
		model.addAttribute("search",search.trim());
		return "member/searchSupplier";
	}
}
